package com.xyzwps.lib.ap.test.ap;

import com.google.auto.service.AutoService;
import com.xyzwps.lib.ap.*;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import java.util.Set;

@AutoService(Processor.class)
@SupportedAnnotationTypes(DataType.TYPE_NAME)
public class DataTypeAp extends AbstractProcessor {
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        var types = ApUtils.getTypes(annotations, roundEnv);
        for (var type : types) {
            System.out.println("====> " + type.getSimpleName());
            System.out.println("    - " + type.asType() + " " + type.asType().getClass().getCanonicalName());
            System.out.println("    - " + type.getKind());
            System.out.println("    - " + type.getSuperclass());
            System.out.println("    - " + type.getModifiers());
            System.out.println("    - " + type.getEnclosedElements());
            var typeInfo = TypeInfo.of(type);
            System.out.println("    - " + Accessors.fromTypeInfo(typeInfo));
        }
        return false;
    }

    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.RELEASE_21;
    }
}
